//初始化数据
$(function() {
	var zjid = getQueryString("zjid");
	$("#zjid").val(zjid);
	var action3 = "/appsfenlei/selectSFenleiByzjid.ph?zjid="+zjid+"";
	var tr = "";
	ajaxWeb(action3, null, function(data3) {
		var obj3 = data3.resobj;
		tr += "<div class=\"pic\">";
		tr += "<img src=\""+obj3.imgpcurl+"\" height=\"295\" width=\"423\" class=\"images_\" alt=\"\">";
		tr += "<p class=\"mask\">最后更新时间"+obj3.updatetime+"</p>";
		tr += "</div>";
		tr += "<div class=\"article\">";
		tr += "<h3 class=\"tit\"><span id=\"titles_\">"+obj3.name+"</span><!--<a href=\"javascript:void(0);\" onclick=\"showtc();\" class=\"a2\">下载</a>--><a href=\"javascript:void(0);\" onclick=\"shoucang('"+zjid+"');\" class=\"a1\">收藏</a></h3>";
		tr += "<p class=\"label\">";
		var bianqian1 = obj3.bianqian1;
		var bianqian2 = obj3.bianqian2;
		var bianqian3 = obj3.bianqian3;
		if(bianqian1) {
			tr += "<span>"+bianqian1+"</span>";
		}
		if(bianqian2) {
			tr += "<span>"+bianqian2+"</span>";
		}
		if(bianqian3) {
			tr += "<span>"+bianqian3+"</span>";
		}
		tr += "</p>";
		tr += "<div class=\"cont\">";
		tr += "<h5>课程简介</h5>";
		tr += "<p>"+obj3.intro+"</p>";
		tr += "</div>";
		
		tr += "</div>";
		$("#jieshao_").html(tr);
	},'json')
	//查询课时列表
	var action3 = "/appsfenlei/selectSFenleiByzjid.ph?zjid="+zjid+"";
	ajaxWeb(action3, null, function(data3) {
		var obj3 = data3.resobj;
		var map = {};
		map["kcid"]=zjid;
		map["page"] = $("#pageIndex").html();
		var action4 = "/appSShipin/selectBykcid.ph";
		var tr = "";
		ajaxPostAsyncData(action4, map, function(data4) {
			if(data4.code=="40000") {
				var obj4 = data4.resobj.rows;
				for(var i=0;i<obj4.length;i++) {
					tr += "<li>";
					tr += "<div class=\"inner\">";
					tr += "<div class=\"pic\"><a href=\"#\"><img src=\""+obj4[i].imgpcurl+"\" alt=\"\"></a></div>";
					tr += "<div class=\"txt\">";
					tr += "<h3><a href=\"kechengxiangqing.html?kcid="+zjid+"&zjid="+obj4[i].zjid+"\"><p class=\"hidde_txt_\">"+obj4[i].name+"</p></a> </h3>";
					tr += "<p><div class=\"ss s1\">"+obj4[i].bofangliang+"</div><div class=\"ss s2\">"+obj4[i].dianzanliang+"</div><div class=\"ss s3\">"+obj4[i].shichang+"</div><a href=\"javascript:void(0);\" onclick=\"showtc();\" class=\"btn-down\"></a></p>";
					tr += "</div>";
					tr += "</div>";
					tr += "</li>";
				}
				$("#kslb").html(tr);
				pageStr(data4,"pageDiv");
			}
		},'json')
	},'json')
	
	//相关推荐
		var action = "/appsfenlei/selectSFenleiByzjid.ph?zjid="+zjid+"";
	ajaxWeb(action, null, function(data) {
		var obj = data.resobj;
		var action2 = "/appsfenlei/selectSFenleiByzjid.ph?zjid="+obj.fflid+"";
		ajaxPostAsyncData(action2, null, function(data2) {
			var obj2 = data2.resobj;
			var action1 = "/appSShipin/selectSp.ph";
			var tr = "";
			var maps = {};
			maps["zjid"]=obj2.fflid;
			maps["index"]=7;
			ajaxPostAsyncData(action1, maps, function(data1) {
				if(data1.code=="40000") {
					var obj1 = data1.resobj.rows;
					tr += "<h3 class=\"lm-tit1 pt10 pb10\"><span>推荐视频</span><a href=\"gengduoshipin.html?zjid="+obj2.fflid+"\">更多</a></h3>";
					tr += "<div class=\"m-more\">";
					tr += "<div class=\"ul-video\" style=\"margin-left:0px;\">";
					tr += "<ul>";
					for(var i=0;i<obj1.length;i++) {
						var action2 = "/appsfenlei/selectSFenleiByzjid.ph?zjid="+obj1[i].kcid+"";
						ajaxPostAsyncData(action2, null, function(data2) {
							tr += "<li style=\"margin-left:10px;\"><a href=\"kechengxiangqing.html?zjid="+obj1[i].zjid+"&kcid="+obj1[i].kcid+"\"><img style=\"width:100%\" src=\""+data2.resobj.imgpcurl+"\" alt=\"\"><p>"+obj1[i].name+"</p></a></li>";
						},'json')
					}
					tr += "</ul>";
					tr += "</div>";
					tr += "</div>";
					$("#tuijian_").html(tr);
				}
			},'json')
		},'json')
	},'json')
});

//课程跳转
function dianji(zjid,kcid) {
	window.location.href="kechengxiangqing.html?kcid="+kcid+"&zjid="+zjid+"";
}

//弹出弹出层
function showtc() {
	$(".bg-black").show();
	$("#down_").show();
}

//关闭弹出层
function close_() {
	$("#down_").hide();
	$(".bg-black").hide();
}

//收藏
function shoucang(zjid) {
	var uid = localStorage.getItem("shipinUid");
	if(uid) {
		var map = {};
		map["ryid"]=uid;
		map["kcid"]=zjid;
		var action3 = "/appSShoucang/insertSShoucang.ph";
		ajaxWeb(action3, map, function(data3) {
			if(data3.code=="40000") {
				$.jBox.tip('收藏成功', 'success');
			}else if(data3.code=="40020") {
				$.jBox.tip('此课程已收藏', 'error');
				return false;
			}else {
				$.jBox.tip('收藏失败', 'error');
				return false;
			}
		},'json')
	}else {
		alert("请您先注册登录，李强365内部原始邀请码限量发放，点击获取！");
		window.open("login.html");
		$.jBox.tip('请先登录', 'error');
		return false;
	}
}

//加载课时列表
function loadData() {
	var zjid = $("#zjid").val();
	//查询课时列表
	var action3 = "/appsfenlei/selectSFenleiByzjid.ph?zjid="+zjid+"";
	ajaxWeb(action3, null, function(data3) {
		var obj3 = data3.resobj;
		var map = {};
		map["kcid"]=zjid;
		map["page"] = $("#pageIndex").html();
		var action4 = "/appSShipin/selectBykcid.ph";
		var tr = "";
		ajaxPostAsyncData(action4, map, function(data4) {
			if(data4.code=="40000") {
				var obj4 = data4.resobj.rows;
				for(var i=0;i<obj4.length;i++) {
					tr += "<li onclick=\"dianji('"+obj4[i].zjid+"','"+zjid+"');\">";
					tr += "<div class=\"inner\">";
					tr += "<div class=\"pic\"><a href=\"javascript:void(0);\"><img src=\""+obj4[i].imgpcurl+"\" alt=\"\"></a></div>";
					tr += "<div class=\"txt\">";
					tr += "<h3><a href=\"kechengxiangqing.html?kcid="+zjid+"&zjid="+obj4[i].zjid+"\"><p class=\"hidde_txt_\">"+obj4[i].name+"</p></a> </h3>";
					tr += "<p><div class=\"ss s1\">"+obj4[i].bofangliang+"</div><div class=\"ss s2\">"+obj4[i].dianzanliang+"</div><div class=\"ss s3\">"+obj4[i].shichang+"</div><a href=\"javascript:void(0);\" onclick=\"showtc();\" class=\"btn-down\"></a></p>";
					tr += "</div>";
					tr += "</div>";
					tr += "</li>";
				}
				$("#kslb").html(tr);
				pageStr(data4,"pageDiv");
			}
		},'json')
	},'json')
}